<!DOCTYPE html>
<HTML>
<HEAD><meta name="viewport" content="width=device-width, initial-scale=1">
<Title>WebChartViewer.streamChart</Title>
<link type='text/css' rel='Stylesheet' href="maxchartapi.css" />
</HEAD>
<body bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">

<p class="heading0">ChartDirector 7.0 (Java Edition)</p>
<p class="heading1"><a href="WebChartViewer.htm">WebChartViewer</a>.<wbr>streamChart</p>
<hr class="separator">
<p class="heading2a">Usage</p>
<div class="content">
public static boolean streamChart(HttpServletResponse response, byte[] image[, String filename[, boolean asAttachment])
</div>
<p class="heading2">Description</p>
<div class="content">
Sends the image out as a MIME stream.<br><br>
The optional <b>filename</b> argument is the suggested filename in case it is needed on the browser side. For example, if the user saves the image to the hard disk, the browser will usually derive a filename based from the URL. For dynamically generated images, the URL is a script, and using it as the image filename may not be meaningful. In this case, the <b>filename</b> can be used to specify the filename to use.<br><br>
The optional <b>asAttachment</b> argument specifies if the MIME stream is an attachment. When the browser receives an attachment, instead of displaying it, it should save it as a file. Some browsers may prompt the user for the directory to use, while others may save it to a special "download directory" without prompting the user.
</div>
<p class="heading2">Arguments</p>
<div class="content">
<div style="width:100%;box-sizing:border-box;">
<table border="1" cellpadding="5" cellspacing="0" width="100%"> 
<tr>
<th width="19%">Argument</th><th width="19%">Default</th><th>Description</th>
</tr>
<tr>
<td>response</td><td>(Mandatory)</td><td>An HttpServletResponse object used to encode the output.</td></tr><tr><td>image</td><td>(Mandatory)</td><td>The in-memory image.</td></tr><tr><td>filename</td><td>""</td><td>The suggested filename to use when user saves the chart image as a file on the browser side.</td></tr><tr><td>asAttachment</td><td>false</td><td>Specifies whether the stream is an attachment.</td>
</tr>
</table>
</div>
</div>
<p class="heading2">Return Value</p>
<div class="content">
This method always return true.<br><br>
<div class="greyblock">
<b><u>Why this method always returns true</u></b><br><br>
In JSP, anything that is outside the code block &lt;% ... %&gt; or &lt;%! ... %&gt; will be sent to the browser as text. Usually, these text are HTML. JSP will translate the text into Java statements that send the text to the browser.<br><br>
The purpose of streamChart is to send the binary image back to the browser. Any text will corrupt the image. So there should be nothing outside the code blocks. In practice, it is common to find invisible empty space or empty lines after the code block. To avoid these invisible text to corrupt the image, after calling streamChart, the code can immediately issue a "return;" statement.<br><br>
However, this does not work for JSP. JSP will still generate the code to sends the invisible text to the browser. These code will never be executed because of the "return;" statement. It is a compiler error in Java to have "unreachable code" - code that can never be executed from the compiler's point of view.<br><br>
To work around this issue, the following code can be used:<br><br>
<code class='pre'>    if (myWebChartViewer.streeamChart(response, myImage))
        return;</code><br>
From the compiler's point of view, the "return;" is conditional, so it is still possible for code after the return statement to execute. In practice, the return statement is always executed because streeamChart always returns true.<br><br>
In summary, the purpose of the "true" return value is to provide a "true" value that is unpredictable to the compiler. This can work around unreachable code automatically generated by JSP.
</div>
</div>
<br><hr class="separator">
<div class="copyright">&copy; 2022 Advanced Software Engineering Limited. All rights reserved.</div>
</body>
</HTML>
